
static std::string MakeFormatString(LPCSTR szFormat, ...)
{
	va_list va;
	char szTemp[2048] = {0,};

	va_start( va, szFormat);
	vsprintf_s( szTemp, _countof(szTemp), szFormat, va);
	va_end( va);

	return std::string(szTemp);
}

static std::string NCharToChar( UINT code_page,LPCWSTR wszName)
{
	char szDestBuff[ MAX_PATH] = {0,};

	if ( MAX_PATH <= wcslen(wszName) )
	{
		_ASSERT(!"Too Long String");
	}

	if(wcslen( wszName) == 0)
		return "";
		

	int result = WideCharToMultiByte( code_page, 0, (LPCWSTR)wszName, wcslen( (LPCWSTR)wszName), szDestBuff, MAX_PATH, NULL, NULL);
	if( result == 0)
	{
		int error_code = GetLastError();
		_ASSERTE(FALSE);
	}

	StringTrimRightA( szDestBuff, MAX_PATH);
	
	return std::string( szDestBuff);
}

static std::wstring CharToNChar(UINT code_page, LPCSTR szName)
{
	WCHAR wszDescBuff[ MAX_PATH] = {0,};

	if ( MAX_PATH <= strlen(szName) )
	{
		_ASSERT(!"Too Long String");
	}

	if(strlen(szName) == 0)
		return L"";

	int result = MultiByteToWideChar( code_page, 0, szName, strlen(szName), wszDescBuff, MAX_PATH);
	if( result == 0)
	{
		int error_code = GetLastError();
		_ASSERTE(FALSE);
	}

	return std::wstring( wszDescBuff);
}

static UINT GetProperCodePage(sShard* pShard)
{
#ifdef __DIVISION_HAS_CODEPAGE__
	LIST_Farm* pFarmList = GetFarmList();
	LIST_Division* pDivList = GetDivisionList();
	LIST_Farm::iterator it, it_end;
	LIST_Division::iterator divit, divit_end;

	it = pFarmList->begin();
	it_end = pFarmList->end();

	for(; it != it_end; ++it)
	{
		sFarm* pFarm = (*it);
		if(pShard->m_nFarmID == pFarm->m_nID)
		{
			divit = pDivList->begin();
			divit_end = pDivList->end();

			for(; divit != divit_end; ++divit)
			{
				sDivision* pDiv = *divit;
				if(pDiv->m_nID == pFarm->m_nDivisionID)
				{
					return pDiv->m_nCodePage;
				}
			}
		}
	}
#endif // #ifdef __DIVISION_HAS_CODEPAGE__

	return 0;
}